var GameData = require('../module/gameData')();
var game_scene = null;
var that = null;
cc.Class({
    extends: cc.Component,
    properties: {
        sp1: cc.Sprite,
        contet: cc.Node,
        coinNum: cc.Label,
        cost: cc.Label,
        watch: cc.Label,
        title: cc.Label,
        nownum: cc.Label,
        addnum: cc.Label,
        tip: cc.Label,
        hand1: dragonBones.ArmatureDisplay,
        hand2: dragonBones.ArmatureDisplay,
        btn1: cc.Sprite,

    },
    /*
    * desc: 其他道具升级界面 例如升级： 氧气瓶，罐头 等
    * author: <zhouzhiwei>
    * @param:
    * date: 2018/10/26
    */
    onLoad() {
    },
    onEnable() {
        /*1,2,3,4,5,6,7,8,9,10*/
        /*1,2,3,4,5,6,7,8,9,10*/
        this.title.string = GameData.gameText.shui.text1;
        this.watch.string = GameData.gameText.shui.btn_text;
        this.tip.string = GameData.gameText.shui.tishi;
        this.updatetext();


    },
    updatetext() {
        this.fishData = GameData.getlocalData("fishData");
        this._level = this.fishData.upgrade.box;
        this.coinNum.string = this.fishData.coinNum + "";


        this.nextLevelCost;
        var addNum;
        if (this._level > 9) {
            this.nextLevelCost = "MAX";
            addNum = this.nextLevelCost + "";
            this.hand1.node.active = false;
            // this.node.getChildByName("right").getChildByName("down").active=false;
        } else {
            var _costNum = GameData.upgradeData.box[this._level].price;
            if (this.fishData.coinNum >= _costNum) {
            }else {
                this.hand1.node.active=false;
                this.cost.node.parent.getComponent(cc.Sprite).spriteFrame=this.btn1.getComponent(cc.Sprite).spriteFrame;
            }
            // this.node.getChildByName("right").getChildByName("down").active=true;
            this.nextLevelCost = GameData.upgradeData.box[this._level].price;
            addNum = "+" + (GameData.upgradeData.box[this._level].Allnum - GameData.upgradeData.box[this._level - 1].Allnum) + "";

        }
        this.cost.string = this.nextLevelCost + "";
        this.nownum.string = GameData.upgradeData.box[this._level - 1].Allnum + "";
        this.addnum.string = addNum;
        for (var a = 0; a < this._level; a++) {
            this.contet.getChildByName("sp" + (a + 1)).getComponent(cc.Sprite).spriteFrame = this.sp1.getComponent(cc.Sprite).spriteFrame;
        }
    },
    selectBtn(evt) {
        let _name = evt.currentTarget.name;
        switch (_name) {
            case "upgrade":
                if (this._level <= 9) {
                    this.hand1.node.active = false;
                    this.fishData = GameData.getlocalData("fishData");
                    var _costNum = GameData.upgradeData.box[this._level].price;
                    if (this.fishData.coinNum >= _costNum) {
                        this.coinNum.node.parent.getComponent("gamecoin").coinAddEffect(this.fishData.coinNum, this.fishData.coinNum - _costNum);

                        this.fishData.coinNum -= this.nextLevelCost;
                        this.fishData.upgrade.box++;
                        GameData.savelocalData(this.fishData);
                        this.updatetext()
                    } else {
                        this.hand1.node.active = false;
                    }
                }
                break;
            case "watch":
                cc.find("watchTv").active = true;
                break;
            case "goback":
        }
    },


    start() {

    },

    // update (dt) {},
});
